layui.define(['form','upload'], function (exports) {
    var $ = layui.jquery;
    var  layer = layui.layer;
    var form = layui.form();
    
    $.post("/srv/rdo.php",{"tpl":"get_period_list3"},function(d){
        $("#period").html(d);
        var periods=$("#period").attr("periods");
        if(periods!=''){
        	periods+=",";
        	$(".period_list").each(function(){
	        	if($.inArray($(this).attr("period"), periods.split(","))!='-1'){
	        		$(this).prop("checked", "checked");
	        	}
	        })
	    }
        form.render("checkbox");
    })
    $.post("/srv/rdo.php",{"tpl":"get_mechanism_list"},function(d){
    	var html = "<option value=''>选择机构</option>"+d;
        $("#mechanism").html(html);
        $("#mechanism").val($("#mechanism").attr("mechanism"));
        form.render('select');
    })
    $.post("/srv/rdo.php",{"tpl":"get_mtype_list"},function(d){
    	var html = "<option value=''>机构类型</option>"+d;
        $("#mtype").html(html);
        $("#mtype").val($("#mtype").attr("mtype"));
        form.render('select');
    })
    $.post("/srv/rdo.php",{"tpl":"get_superior_list"},function(d){
    	var html = "<option value=''>选择所属</option>"+d;
        $("#superior").html(html);
        $("#superior").val($("#superior").attr("superior"));
        form.render('select');
    })
    $.post("/srv/rdo.php",{"tpl":"get_dict_list"},function(d){
    	var html = "<option value=''>选择地区</option>"+d;
        $("#dict").html(html);
        $("#dict").val($("#dict").attr("dict"));
        form.render('select');
    })
    layui.upload({
	    url: '/html/system/srv/upd_school_logo.php' //上传接口
	    ,ext: 'jpg|png|gif'
	    ,success: function(res){ //上传成功后的回调
	        //console.log(res);
	        if(res.ret=='ok'){
	        	$("#show_logo").attr("src","/upload/school_logo/"+res.fname);
	        	$("#sch_logo").val(res.fname);
	        }
	    }
    });
    var index = parent.layer.getFrameIndex(window.name);
    $('#btn_save').click(function(){
        if($("#sch_name").val()==""){layer.msg("学校名称不能为空");return false;}

        $.post("/html/system/srv/edit_school.php", $("#form1").serialize(), function (d, e) {
            if(d=="ok"){
                layer.msg("保存成功！");
                setTimeout("parent.layer.close(parent.layer.getFrameIndex(window.name));",1500);
            }else{
                layer.msg(d);
                console.log(d);
            }
        });
    });
     
    exports('system_edit_school', {});
});